var app = getApp();
Component({
    properties: {
        paycard : Array,
    },
    data:{
        isshowpaycard : false,
        value:'',
        paynumber : '',
        paymonth : '',
        payyear : '',
        paycvc : '',
        email : '',
    },
    options : {
        addGlobalClass : true,
    },
    methods: {
        confirm : function(obj){
            this.triggerEvent('setpaycard',obj);
        },
        show : function(e){
            this.setData({
                isshowpaycard : true,
            })
        },
        hide(){
            this.setData({
                isshowpaycard : false,
            })
        },
        setpaycard(e){
            var self = this;
            var type = e.currentTarget.dataset.type;
            if(type == 'old'){
                var item = this.data.paycard[e.detail.value];
                self.confirm({
                    paynumber : item.number,
                    paycid : item.cid,
                })
                self.hide();
            }else if(type == 'confirm'){
                var postdata = {
                    paynumber : self.data.paynumberi ? self.data.paynumberi : '',
                    paymonth : self.data.paymonthi ? self.data.paymonthi : '',
                    payyear : self.data.payyeari ? self.data.payyeari : '',
                    paycvc : self.data.paycvci ? self.data.paycvci : '',
                    email : self.data.emaili ? self.data.emaili : '',
                    op:'addpaycard',
                };
                app.com.http('user_v1','POST',postdata,0,true,'','',function(res){
                    if (!res.data.errno  && res.data) {
                        self.confirm({
                            paynumber : postdata.paynumber,
                            paycid : res.data.data.cid,
                        })
                        self.hide();
                    }else{
                        app.com.toast(res.data.message);
                    }
                });
            }else{
                this.setData({
                    [type] : e.detail.value
                })
            }
        }
    }

})